#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+5;
ll T,a[N],ans,n;
void dfs(ll dep,ll red,ll blue,ll sum){
	if(dep>n){
		ans=max(ans,sum);
		return;
	}
	if(a[red]==a[dep])	dfs(dep+1,dep,blue,sum+a[dep]);
	else 	dfs(dep+1,dep,blue,sum);
	if(a[blue]==a[dep])	dfs(dep+1,red,dep,sum+a[dep]);
	else 	dfs(dep+1,red,dep,sum);
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n;
		ans=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		dfs(1,0,0,0);
		cout<<ans<<endl;
	}
	return 0;
}
